import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:myflutter/math/running_page.dart';
import 'package:myflutter/math/testmessages.dart';

import 'package:flutter_math_fork/flutter_math.dart';


import 'package:shared_preferences/shared_preferences.dart';

import 'Personal_Page.dart';

void printout(){
  print("按钮测试");
}

RunningPage runningPage = RunningPage();
PersonalPage personalPage = PersonalPage();

Color primaryColor = Color.fromARGB(255, 206, 106, 140);

class MyAppBars extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '高数',
      home: MyHomePage(),
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primaryColor: primaryColor,
      ),
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: const [
        Locale('zh'),
      ],
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => NavPageState();

}

class NavPageState extends State<MyHomePage> {
  int _currentIndex = 0;
  Map<int,Map<String,List<Icon>>> titleName = {
    0:{"运行": [Icon(Icons.play_arrow_outlined),Icon(Icons.play_arrow)]},
    1:{"个人页": [Icon(Icons.person_outline_sharp,),Icon(Icons.person_sharp)]},

  };

  Map<int,Widget> pageList = {
    0:runningPage,
    1:personalPage,
  };

  Map<int,FloatingActionButton> floatbuttonList = {
    0:FloatingActionButton(
      backgroundColor: primaryColor,
      onPressed: printout,
      tooltip: '新增计算',
      child: const Icon(Icons.add),
    )
  };

  List<BottomNavigationBarItem> getBarItem(){
    List<BottomNavigationBarItem> inner = [];
    titleName.forEach((key, value) {
      value.forEach((key1, value1) {
        inner.add(
            BottomNavigationBarItem(icon: value1[0], label: key1, activeIcon: value1[1],)
        );
      });
    });
    return inner;
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('${titleName[_currentIndex]?.keys.first}',style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold),),
        backgroundColor: Theme.of(context).primaryColor,
        elevation: 0,
        toolbarHeight: 70,
      ),
      backgroundColor: Color.fromARGB(255, 240, 240, 240),
      body: pageList[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex,
        onTap: (int index){
          setState((){
            _currentIndex = index;
            runningPage.setT(runningPage.getT().toString());
          });
        },
        items: getBarItem(),
        iconSize: 35,

        selectedItemColor: Theme.of(context).primaryColor,
        unselectedItemColor: Color.fromARGB(255, 135, 91, 107),
        backgroundColor: Color.fromARGB(255, 255, 255, 255),
        elevation: 20,
      ),
      floatingActionButton: floatbuttonList[_currentIndex],
    );
  }

}
// class BarPageState extends State<MyHomePage> {
//
//   @override
//   Widget build(BuildContext context) {
//     return DefaultTabController(length: 3, child: Scaffold(
//       appBar: AppBar(
//         toolbarHeight: 80,
//         backgroundColor: Color.fromARGB(255, 201, 11, 79),
//         title: Text('主页',
//           style: TextStyle(
//               fontSize: 34,
//               fontWeight: FontWeight.bold,
//             color: Color.fromARGB(255, 255, 255, 255)
//           ),
//         ),
//         bottom: TabBar(
//           unselectedLabelColor: Color.fromARGB(255, 78, 24, 61),
//           labelColor: Color.fromARGB(255, 143, 180, 240),
//           indicatorColor: Color.fromARGB(255, 152, 190, 248),
//
//           // 选项卡
//           tabs: [
//             Tab(text: 'Tab1'),
//             Tab(text: 'Tab2'),
//             Tab(text: 'Tab3'),
//           ],
//         ),
//       ),
//       body: TabBarView(
//         // 选项卡对应的视图
//         children: [
//           Center(
//             child: Column(
//               mainAxisAlignment: MainAxisAlignment.center,
//               children: [
//                 Image(
//                   image: AssetImage("assets/images/volume.png"),
//                   height: 140,
//                   width: 140,
//                 ),
//                 Divider(
//                   color: Colors.white10,
//                   height: 20,
//                 ),
//                 Text("应用程序图标展示"),
//               ],
//             )
//           ),
//           Center(
//             child: Text('Tab2'),
//           ),
//           Center(
//             child: Text('Tab3'),
//           ),
//         ],
//       ),
//     )
//     );
//   }
// }